package com.woniu.service.Impl.backpage;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.dao.backpage.GoodsDao;
import com.woniu.entity.Goods;
import com.woniu.entity.RushPurchase;
import com.woniu.service.backpage.IGoodsService;
import com.woniu.util.RequestParams;
import com.woniu.util.ResData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements IGoodsService {

    @Autowired(required = false)
    private GoodsDao goodsDao;

    @Override
    public ResData<?> findGoodsByConditions(RequestParams<Goods> requestParams) {
        PageHelper.startPage(requestParams.getPageNo(),requestParams.getPageSize());
        PageInfo<Goods> goodsPageInfo=new PageInfo<>(goodsDao.findGoodsByConditions(requestParams.getData().getName(),
                requestParams.getData().getTypeName(),requestParams.getData().getPutOn(),requestParams.getData().getMinPrice(),requestParams.getData().getMaxPrice()));
        return new ResData<>().ok(goodsPageInfo);
    }

    @Override
    public ResData<?> deleteGoods(RequestParams<Goods> requestParams) {
        goodsDao.deleteGoods(requestParams.getData().getId(),requestParams.getData().getPutOn());
        return new ResData<>().ok();
    }

    @Override
    public ResData<?> insertGoods(Goods goods) {
        goodsDao.insertGoods(goods);
        return new ResData<>().ok();
    }

    @Override
    public ResData<?> updateRushPurchaseStatus(RushPurchase rushPurchase) {
        goodsDao.updateRushPurchaseStatus(rushPurchase);
        return new ResData<>().ok();
    }

    @Override
    public ResData<?> updateGoods(Goods goods) {
        goodsDao.updateGoods(goods);
        return new ResData<>().ok();
    }

    @Override
    public ResData<?> findGoodsByName(String name) {
        return new ResData<>().ok(goodsDao.findGoodsByName(name));
    }

    @Override
    public ResData<?> insertRushPurchase(RushPurchase rushPurchase) {
        goodsDao.insertRushPurchase(rushPurchase);
        return new ResData<>().ok();
    }

    @Override
    public ResData<?> batchInsertGoodsImage(Integer goodsId, List<Integer> tagIds) {
        goodsDao.batchInsertGoodsImage(goodsId,tagIds);
        return new ResData<>().ok();
    }

}
